﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EF6Sample
{
    public class SqlDbContext : DbContext
    {
        public SqlDbContext() : base("17bang")
        {
            //从控制台输出
            Database.Log = Console.WriteLine;
            ////从VS的out window输出
            //Database.Log = s => Debug.Write(s);
            ////写入磁盘文件：c:\\ef.log
            //Database.Log = s => File.AppendAllText("c:\\ef.log", s);
        }
        public DbSet<Student> Students { get; set; }
        public DbSet<Teacher> Teachers { get; set; }
        public DbSet<Person> Persons { get; set; }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //modelBuilder.Entity<Student>()
            //    .Property(s => s.Name).HasMaxLength(50)
            //    ;
            //modelBuilder.Entity<Student>()
            //    .Property(s => s.Score).IsOptional()
            //    ;
            //modelBuilder.Entity<Student>()
            //    .HasIndex(s => s.Score)
            //    ;
            //modelBuilder.Entity<Person>().ToTable("Persons");
            //modelBuilder.Entity<Student>()
            //    .Map(m =>
            //    {
            //        m.MapInheritedProperties();
            //        m.ToTable("Students");
            //    });
                
            //modelBuilder.Entity<Teacher>()
            //    .Map(m =>
            //    {
            //        m.MapInheritedProperties();
            //        m.ToTable("Teachers");
            //    });
            //modelBuilder.Entity<Student>()
            //    .HasOptional(s => s.SleepIn)
            //    //.WithRequiredPrincipal()
            //    .WithOptionalDependent(b=>b.Owner)
            //    ;
            base.OnModelCreating(modelBuilder);
        }
    }
}
